package com.tangdi.Dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.tangdi.Bean.User;
import com.tangdi.common.DBConnect;

public class userDaoImpl {
	Connection con=DBConnect.getInstance().getConnection();
	PreparedStatement pstmt=null;
	ResultSet rs=null;
	
	public boolean checkUser(String name,String password){
		boolean b=false;
		String sql="select * from hr_user where name='"+name+"' and password='"+password+"'";
		try{
			pstmt=con.prepareStatement(sql);
			rs=pstmt.executeQuery();
			while(rs.next()){
				b=true;
			}
		}catch(SQLException e){
			e.printStackTrace();
		}
		return b;
	}
	
	
	public boolean checkAdmin(String name,String password){
		boolean b=false;
		String sql="select * from admin_user where name='"+name+"' and password='"+password+"'";
		System.out.println(sql);
		try{
			pstmt=con.prepareStatement(sql);
			rs=pstmt.executeQuery();
			while(rs.next()){
				b=true;
			}
		}catch(SQLException e){
			e.printStackTrace();
		}
		return b;
	}
	
	
	public List<User> listUser(){
		List<User> listuser=new ArrayList<User>();
		String sql="select * from hr_user";
		try{
			pstmt=con.prepareStatement(sql);
			rs=pstmt.executeQuery();
			while(rs.next()){
				User user=new User();
				user.setName(rs.getString(1));
				user.setPassword(rs.getString(2));
				listuser.add(user);
			}
		}catch(SQLException e){
			e.printStackTrace();
		}
		
		
		return listuser;
	}
}
